package com.example.demo.question4;

import com.example.demo.entity.ReturnData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Future;

@RestController
public class MyAsyncController {
    @Autowired
    private MyAsyncServices myService;

    @GetMapping("/statistics")
    public ReturnData statistics() throws Exception {
        int total = 0;
        Long startTime = System.currentTimeMillis();
        // 1、启动有返回值的异步任务A
        // 2、启动有返回值的异步任务B
        // 3、获取A、B异步任务的返回值，并相加赋值给total
        System.out.println("异步任务数据统计汇总结果： "+total);
        Long endTime = System.currentTimeMillis();
        System.out.println("主流程耗时： "+(endTime-startTime) + "毫秒");
        return ReturnData.ok("执行成功返回值为："+total);
    }


}
